package com.ruoyi.web.controller.interfaceConfig.sceneConfig;

import java.util.List;
import java.util.Objects;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.interfaceConfig.sceneConfig.domain.dto.SceneConfigDTO;
import com.ruoyi.interfaceConfig.sceneConfig.domain.vo.SceneConfigVo;
import com.ruoyi.interfaceConfig.sceneConfig.domain.vo.SceneSearchParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lombok.RequiredArgsConstructor;
import com.ruoyi.interfaceConfig.sceneConfig.domain.SceneConfig;
import com.ruoyi.interfaceConfig.sceneConfig.service.ISceneConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 集成场景配置Controller
 * 
 * @author YiYuan
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/interfaceConfig/sceneConfig")
@RequiredArgsConstructor
public class SceneConfigController extends BaseController
{
    private final ISceneConfigService sceneConfigService;

    /**
     * 查询集成场景配置列表
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SceneConfig sceneConfig)
    {
        startPage();
        List<SceneConfigVo> list = sceneConfigService.selectSceneConfigList(sceneConfig);
        return getDataTable(list);
    }

    /**
     * 导出集成场景配置列表
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:export')")
    @Log(title = "集成场景配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SceneConfig sceneConfig)
    {
        List<SceneConfigVo> list = sceneConfigService.selectSceneConfigList(sceneConfig);
        ExcelUtil<SceneConfigVo> util = new ExcelUtil<SceneConfigVo>(SceneConfigVo.class);
        util.exportExcel(response, list, "集成场景配置数据");
    }

    /**
     * 获取集成场景配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sceneConfigService.selectSceneConfigById(id));
    }

    /**
     * 新增集成场景配置
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:add')")
    @Log(title = "集成场景配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SceneConfig sceneConfig)
    {
        if(Objects.isNull(sceneConfig.getSysObjId1()) || Objects.isNull(sceneConfig.getSysObjId2())) {
            return AjaxResult.error("未检测到选择的场景对象");
        }
        return success(sceneConfigService.insertSceneConfig(sceneConfig));
    }

    /**
     * 修改集成场景配置
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:edit')")
    @Log(title = "集成场景配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SceneConfig sceneConfig)
    {
        return toAjax(sceneConfigService.updateSceneConfig(sceneConfig));
    }

    /**
     * 删除集成场景配置
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:remove')")
    @Log(title = "集成场景配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sceneConfigService.deleteSceneConfigByIds(ids));
    }

    /**
     * 获取集成场景配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:fieldMapping')")
    @GetMapping(value = "/getSceneConfigDetail/{id}")
    public AjaxResult getSceneConfigDetail(@PathVariable("id") Long id)
    {
        return success(sceneConfigService.getSceneConfigDetail(id));
    }

    //查询接口
    @PreAuthorize("@ss.hasPermi('interfaceConfig:sceneConfig:getSceneSearchList')")
    @GetMapping(value = "/getSceneSearchList")
    public TableDataInfo getSceneSearchList(SceneSearchParams sceneSearchParams)
    {
        startPage();
        List<SceneConfigDTO> list = sceneConfigService.getSceneSearchList(sceneSearchParams);
        return getDataTable(list);
    }

}
